package project3t.android.gui;

import project3t.android.control.Controller;
import project3t.android.data.Person;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class PersonInfo extends Activity{

	private TextView name,surname,age,sex,email;	
	private Person person;
	private int itemIndex;
	public PersonInfo()
	{
		super();
	}
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.person_info);
		Bundle bun=getIntent().getExtras();
		itemIndex=bun.getInt("index");
//		person=Controller.conroller.getPersonByPos(itemIndex);
//		name= (TextView) findViewById(R.id.name);		
//		surname=(TextView) findViewById(R.id.surname);
//		age=(TextView) findViewById(R.id.age);
//		sex=(TextView) findViewById(R.id.sex);
//		email=(TextView) findViewById(R.id.email);
//		name.setText(person.getName());
//		surname.setText(person.getSurname());
//		age.setText(String.valueOf(person.getAge()));
//		sex.setText(String.valueOf(person.getSex()));
//		email.setText(person.getEmail());
	}
	
	@Override
	public void onStart() 
	{
		super.onStart();
		person=Controller.conroller.getPersonByPos(itemIndex);
		name= (TextView) findViewById(R.id.name);		
		surname=(TextView) findViewById(R.id.surname);
		age=(TextView) findViewById(R.id.age);
		sex=(TextView) findViewById(R.id.sex);
		email=(TextView) findViewById(R.id.email);
		name.setText(person.getName());
		surname.setText(person.getSurname());
		age.setText(String.valueOf(person.getAge()));
		sex.setText(String.valueOf(person.getSex()));
		email.setText(person.getEmail());
	}
	
	public void deletePerson(View view)
	{
		Controller.conroller.deletePerson(itemIndex);					
		finish();
	}
	public void editPerson(View view)
	{
		//Controller.conroller.editPerson(itemIndex);
		Intent intent = new Intent(Intent.ACTION_VIEW);
		intent.setClassName(PersonInfo.this, EditForm.class.getName());
		Bundle extras=new Bundle();
		extras.putInt("index", itemIndex);
		intent.putExtras(extras);
		startActivity(intent);
	}
}
